﻿//结束游戏对话框
package com.victim.snake.graphics.playClass
{
	import flash.display.Sprite;
	import com.victim.snake.graphics.mainClass.GrayTranDiv;
	import com.victim.snake.util.GraphicsToll;
	import flash.text.TextField;
	import fl.controls.Button;
	import flash.events.MouseEvent;
	import com.victim.snake.user.User;
	import com.victim.snake.user.Msg;
	
	public class GameOverSprite extends Sprite{
		
		var backgroundSprite:GrayTranDiv=new GrayTranDiv();	//半透明灰色背景
		var okSprite:Sprite=new Sprite();	//ok对话框
		var winOrLose:TextField=new TextField();	//输赢字符串
		var okButton:Button=new Button();	//ok按钮
		
		//构造函数
		public function GameOverSprite(msg:Msg){
			this.addChild(backgroundSprite);
			this.addChild(okSprite);
			this.addChild(winOrLose);
			this.addChild(okButton);
			
			//ok对话框
			okSprite.graphics.beginFill(0xffffff,1);
			okSprite.graphics.drawRect(100,70,300,200);
			okSprite.graphics.endFill();
			
			
			//输赢字符串
			
			winOrLose.text=msg.getUTF8Content();
			
			winOrLose.x=238;
			winOrLose.y=158;
			
			//ok按钮
			okButton.label="确定";
			okButton.x=198;
			okButton.y=230;
			okButton.addEventListener(MouseEvent.CLICK,okButtonEvent);
		}
		
		//ok按钮事件
		public function okButtonEvent(event:MouseEvent):void{
			//将房间初使化
			User.getRoom().init();	
			User.getRoomSprite().refreshState();
			
			//删除舞台上所有界面
			var numChildren=User.getStage().numChildren;
			for(var i:int=0;i<numChildren;i++){
				User.getStage().removeChildAt(0);
			}
			//显示房间界面
			User.getStage().addChild(User.getRoomSprite());
		}
	}
}